package com.gongpingjialoan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.bean.HotCarBean;
import com.gongpingjialoan.imageload.ImageLoad;
import com.gongpingjialoan.utility.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class HotAdapter extends BaseAdapter {
    private List<HotCarBean> mHotCarBeans;
    private Context mContext;

    public HotAdapter(List<HotCarBean> hotCarBeans, Context context) {
        mHotCarBeans = hotCarBeans;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mHotCarBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return mHotCarBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.hot_item, parent , false);
        }
        TextView titleTextView = BaseViewHolder.get(convertView, R.id.name);
        ImageView networkImageView = BaseViewHolder.get(convertView, R.id.image);
        View line =  BaseViewHolder.get(convertView, R.id.line);
        titleTextView.setText(mHotCarBeans.get(position).getName());
        if(mHotCarBeans.get(position).getIsShowImg()) {
            networkImageView.setVisibility(View.VISIBLE);
            ImageLoad.LoadImage(networkImageView, mHotCarBeans.get(position).getUrl(), R.drawable.brandnull, R.drawable.brandnull,mContext);
        }else{
            networkImageView.setVisibility(View.GONE);
        }
        if((position+1)%4 == 0){
            line.setVisibility(View.GONE);
        }else{
            line.setVisibility(View.VISIBLE);
        }
        return convertView;
    }
}
